package com.team2.insulatingtools.modular.tools.controller;

import com.team2.insulatingtools.modular.tools.dto.SetKeeperDto;
import com.team2.insulatingtools.modular.tools.entity.ToolDetail;
import com.team2.insulatingtools.modular.tools.entity.Tools;
import com.team2.insulatingtools.modular.tools.pojo.request.ReminderRequest;
import com.team2.insulatingtools.modular.tools.pojo.request.ToolsRequest;
import com.team2.insulatingtools.modular.tools.pojo.response.ToolReminderResponse;
import com.team2.insulatingtools.modular.tools.service.ToolsService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 绝缘工具 控制器
 *
 * @author team2
 * @date 2023/04/07 16:03
 */
@RestController
@ApiResource(name = "绝缘工具 ")
public class ToolsController {

    @Resource
    private ToolsService toolsService;

    /**
     * 添加
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @PostResource(name = "添加", path = "/tools/add")
    public ResponseData<?> add(@RequestBody @Validated(ToolsRequest.add.class) ToolsRequest toolsRequest) {
        return toolsService.add(toolsRequest);
    }

    /**
     * 删除
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @PostResource(name = "删除", path = "/tools/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ToolsRequest.delete.class) ToolsRequest toolsRequest) {
        return toolsService.del(toolsRequest);
    }

    /**
     * 编辑
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @PostResource(name = "编辑", path = "/tools/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ToolsRequest.edit.class) ToolsRequest toolsRequest) {
        toolsService.edit(toolsRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @GetResource(name = "查看详情", path = "/tools/detail")
    public ResponseData<Tools> detail(@Validated(ToolsRequest.detail.class) ToolsRequest toolsRequest) {
        return new SuccessResponseData<>(toolsService.detail(toolsRequest));
    }

    /**
     * 获取列表
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @GetResource(name = "获取列表", path = "/tools/list")
    public ResponseData<List<Tools>> list(ToolsRequest toolsRequest) {
        return new SuccessResponseData<>(toolsService.findList(toolsRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author team2
     * @date 2023/04/07 16:03
     */
    @GetResource(name = "分页查询", path = "/tools/page")
    public ResponseData<PageResult<Tools>> page(ToolsRequest toolsRequest) {
        return new SuccessResponseData<>(toolsService.findPage(toolsRequest));
    }

    @PostResource(name = "保管人", path = "/tools/keeper")
    public ResponseData changeKeeper(@RequestBody ToolsRequest toolsRequest) {
        toolsService.changeKeeper(toolsRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 过期提醒
     *
     * @author team2
     * @date 2023/04/03 09:48
     */

//    @GetResource(name = "通过车间查询", path = "/tools/selbyworkshop")
//    public ResponseData selByWorkshop(String speciality, String workshopName, String groupName) {
//        return new SuccessResponseData<>(toolsService.selByWorkshop(speciality, workshopName, groupName));
//    }
    @GetResource(name = "通过车间查询", path = "/tools/selbyworkshop")
    public ResponseData selByWorkshop(String speciality, String orgName) {
        return new SuccessResponseData<>(toolsService.selByOrgName(speciality, orgName));
    }

    @GetResource(name = "过期提醒", path = "/tools/reminder")
    public List<ToolReminderResponse> getExpireIn(ReminderRequest reminderRequest) {
        return toolsService.getToolAboutToExpire(reminderRequest);
    }

    //    @GetResource(name = "通过车间和工具名查询", path = "/tools/selbyworkshopandtools")
//    public ResponseData selByWorkshopAndTools(String speciality, String workshopName, String groupName, String categoryName) {
//        return new SuccessResponseData<>(toolsService.SelByWorkshopAndTools(speciality, workshopName, groupName, categoryName));
//    }
    @GetResource(name = "通过车间和工具名查询", path = "/tools/selbyworkshopandtools")
    public ResponseData selByWorkshopAndTools(String speciality, String orgName, String categoryName) {
        return new SuccessResponseData<>(toolsService.SelByOrgNameAndTools(speciality, orgName, categoryName));
    }

    //    @PostResource(name = "通过车间保管人", path = "/tools/keepers")
//    public ResponseData changeKeepers(@RequestBody Map<String, String> map) {
//        toolsService.changeKeeperBatch(Integer.parseInt(map.get("id")), map.get("keeper"));
//        return new SuccessResponseData<>();
//    }
    @PostResource(name = "通过车间保管人", path = "/tools/keepers")
    public ResponseData changeKeepers(@RequestBody SetKeeperDto dto) {
        toolsService.changeKeeperBatch(dto);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "通过工具id查询keeper的历史记录", path = "/tools/showkeeperlog")
    public ResponseData showKeeperLog(int tid) {
        return new SuccessResponseData<>(toolsService.showKeeperLog(tid));
    }
}
